/*
 * contextmenu 2016.6 by CSS WeidongWang
 */
(function($) {
 	var menuMap = {};
  $.fn.contextMenu = function(id, options) {
  	var menu;
 		if(!(id in menuMap))
	  	menuMap[id]=$('#'+id).clone(true).appendTo('body');
	 	menu=menuMap[id];
    var a=$(this);
    a.contextmenu(function(e) {
   		$.each(options.callback,function(id,func){
    		menu.find('[rel='+id+']').off().on('click',function(){
        	func(a);
      	})
      });
    	if(options.init) options.init(a, menu);
      var top = e['pageY'] + menu.height();
      var offset = $(window).height() -top -10;
      top= offset>0? e['pageY']: e['pageY']+offset;
      menu.css({'left':e['pageX'],'top':top}).show();
	    $(document).one('click', function(){
      	menu.hide();
      });
	    return false;
    });
  };
})(jQuery);